package objects.slots;

import java.util.ArrayList;
import objects.DataObject;

public class ListSlot<E extends DataObject> extends Slot<E> {
	int index;
	Position position;
	ArrayList<E> list;
	
	public ListSlot( ArrayList<E> list, int index, Position position ) {
		this.list = list;
		this.index = index;
		this.position = position;
	}

	@Override
	public void insert( E value ) {
		switch( position ) {
			case BEFORE:
				list.add( index, value );
				break;
			case INSTEAD:
				list.set( index, value );
				break;
			case AFTER:
				list.add( index + 1, value );
				break;
		}		
	}

	@Override
	public E remove() {
		return list.remove( index );
	}
}
